/*
 *  Getris -- A Tetris game written in Groovy.
 *  Copyright (C) 2008 Johnny Jian
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
package cn.johnnyjian.getris.panel

import groovy.swing.SwingBuilder
import java.awt.Color
import java.awt.Font
import javax.swing.Box

class InfoPanel extends FramePanel {

	def scoreLabel
	def score
	def level
	def lines

	InfoPanel(tetris) {
		def labelFont = new Font('SansSerif', Font.PLAIN, 18)
		def scoreFont = new Font('SansSerif', Font.BOLD, 20)

		def swing = new SwingBuilder()
		add(swing.box(Box.createVerticalBox()) {
			scoreLabel = label(alignmentX: CENTER_ALIGNMENT, foreground: Color.WHITE, font: labelFont)
			score = label(alignmentX: CENTER_ALIGNMENT, foreground: Color.YELLOW, font: scoreFont)
			widget(Box.createVerticalStrut(5))
			level = label(alignmentX: CENTER_ALIGNMENT, foreground: Color.WHITE, font: labelFont)
			lines = label(alignmentX: CENTER_ALIGNMENT, foreground: Color.WHITE, font: labelFont)
		})

		tetris.addObserver({ o, game ->
			scoreLabel.text = 'Score'
			score.text = "$game.scoreKeeper.score"
			level.text = "Level $game.scoreKeeper.level"
			lines.text = "$game.scoreKeeper.lines Lines"
		} as Observer)
	}

}
